/*
============================================================================
Name		: DemoView.cpp
Author	  : hou maoqing
Version	 : 1.0
Copyright   : Your copyright notice
Description : CDemoView implementation
============================================================================
*/
#include "DemoView.h"
#include "RtEnv.h"
#include "RtUiManager.h"
#include "RtCommand.h"
#include "RtMenuData.h"
#include "RtUiRes.h"
#include "RtWeiboApp.h"
#include "RtWeiboCmd.h"
#include "RtTextReader.h"
#include "RtWeiboApp.h"

IMPLEMENT_CLASS(CDemoView);

CDemoView::CDemoView()
:CRtXmlView()
{
	REGISTER_ACTCON(Back);
	REGISTER_ACTCON(Exit);
}

CDemoView::~CDemoView()
{
	Unload();
}

void CDemoView::ConstructL()
{	
	//初始化CBA栏
	SetCbaData(ERtShowMenu,CRtEnv::GetString(RTS_UI_MENU),ERtBack,CRtEnv::GetString(RTS_UI_BACK));

	REGISTER_ACTCON(Back);
	REGISTER_ACTCON(Exit);
}

void CDemoView::DoActivating()
{
	if(!IsLoaded())
	{
		DBGPRINTF("1");
		CRtString strFormFile = CRtWeiboApp::Static()->GetXmlUiPath("DemoView.xml");
		Load(strFormFile);
		CRtRect rectClient=GetView()->GetUiManager()->GetClientRect();
		SetRect(rectClient);
		DBGPRINTF("2");

	}

	//int n=12;
	//char buf[100];

	//sprintf(buf,"hello,today is cool, %d",n++);
	//CRtWeiboApp::Static()->GetWeiboEngine()->PostStatusesUpdate(buf/*,CRespReceiver(0,"Back")*/);
}

void CDemoView::DoDeactivate()
{
	if(IsLoaded())
		{
		Unload();
		DBGPRINTF("1");
		}
}

void CDemoView::Draw(CRtGc& gc,const CRtRect& rect)
{
//	gc.SetDrawStyle(CRtGc::ERtDrawStroke);
//	gc.SetDrawColor(CRtRgb(0xbb,0,0));
//	gc.DrawEllipse(rect);
}

bool CDemoView::Back(CRtEvtSender* pSender,CRtMessage* pMessage)
{
	GetUiManager()->ActivateView(ERtWeiboMainViewID);
	return true;
}

bool CDemoView::Exit(CRtEvtSender* pSender,CRtMessage* pMessage)
{
	GetUiManager()->Stop();
	return true;
}


bool CDemoView::HandleMessage(CRtMessage* pMsg)
	{
	bool bRes=false;
		switch(pMsg->m_uiMessage)
		{
	      case EWeiboRespMsg:
	      {
		         if(pMsg->m_lParam)
		   {
			CRtString* pStr=(CRtString*)pMsg->m_lParam;
			CRtXmlForm* pForm=this->GetForm();
			CRtTextReader* p=(CRtTextReader*)pForm->GetControl("disp_msg");
			p->SetText(*pStr);
			delete pStr;
		    }
		    break;
	      }
		default:
			break;
		}
	  return bRes;
    }


   //void CDemoView::DynInitMenuData(CRtMenuData* pMenuData)
//	{
//	//set menuitem show/hide
////	pMenuData->MakeItemVisible(ECreatePlayList,false);
////	pMenuData->MakeItemVisible(EDeletePlayList,false);
////	pMenuData->MakeItemVisible(EAppendAllMusic,true);
//	} 